<template>
<div>
  <cfg-field :mark="false" :label="lang.name" v-model="data.name" :config="{type:'text'}"></cfg-field>
  <cfg-field :mark="false" :label="lang.title" v-model="data.title" :config="{type:'text'}"></cfg-field>
  <cfg-field :mark="false" :label="lang.model" v-model="data.model" :config="{type:'select',options:modelList}"></cfg-field>
<!--  <cfg-entity-instance-pointer v-if="data.model==='entity'" :label="lang.pointer" v-model="data.pointer"></cfg-entity-instance-pointer>-->
<!--  <cfg-twins-instance-pointer v-if="data.model==='twins'" :label="lang.pointer" v-model="data.pointer"></cfg-twins-instance-pointer>-->
<!--  <cfg-logic-instance-pointer v-if="data.model==='logic'" :label="lang.pointer" v-model="data.pointer"></cfg-logic-instance-pointer>-->
<!--  <cfg-template-instance-pointer v-if="data.model==='template'" :label="lang.pointer" v-model="data.pointer"></cfg-template-instance-pointer>-->
  <cfg-entity-model-pointer v-if="data.model==='entity'" :label="lang.pointer" v-model="data.pointer"></cfg-entity-model-pointer>
  <cfg-twins-model-pointer v-if="data.model==='twins'" :label="lang.pointer" v-model="data.pointer"></cfg-twins-model-pointer>
  <cfg-logic-model-pointer v-if="data.model==='logic'" :label="lang.pointer" v-model="data.pointer"></cfg-logic-model-pointer>
  <cfg-template-model-pointer v-if="data.model==='template'" :label="lang.pointer" v-model="data.pointer"></cfg-template-model-pointer>
  <cfg-statistics-model-pointer v-if="data.model==='statistics'" :label="lang.pointer" v-model="data.pointer" />
  <cfg-field :mark="false" :label="lang.condition" :labelStyle="{height:'52px'}" :config="{type:'textarea'}" v-model="data.condition" />
  <cfg-map-wrapper :title="lang.values">
    <template #default>
      <cfg-field :mark="false" v-for="item in Object.keys(data.values)" :key="item"
      :config="{type:'text'}" :label="item" v-model="data.values[item]" :removeField="true"
        @removeField="removeValue(item)"></cfg-field>
    </template>
    <template #empty>
      <cfg-empty :mark="false" :label="lang.newValue" :config="{type:'text'}" v-model="newValue"
      :addField="true" @addField="addValue"></cfg-empty>
    </template>
  </cfg-map-wrapper>
</div>
</template>

<script>
import CfgField from "../../../wizard/fields/cfg-field";
import CfgCell from "../../../wizard/fields/cfg-cell";
import CfgEntityInstancePointer from "../../../wizard/fields/cfg-entity-instance-pointer";
import CfgTwinsInstancePointer from "../../../wizard/fields/cfg-twins-instance-pointer";
import CfgLogicInstancePointer from "../../../wizard/fields/cfg-logic-instance-pointer";
import CfgTemplateInstancePointer from "../../../wizard/fields/cfg-template-instance-pointer";
import CfgMapWrapper from "../../../wizard/map/cfg-map-wrapper";
import CfgEmpty from "../../../wizard/fields/cfg-empty";
import CfgEntityModelPointer from "../../../wizard/fields/cfg-entity-model-pointer";
import CfgTwinsModelPointer from "../../../wizard/fields/cfg-twins-model-pointer";
import CfgLogicModelPointer from "../../../wizard/fields/cfg-logic-model-pointer";
import CfgTemplateModelPointer from "../../../wizard/fields/cfg-template-model-pointer";
import CfgStatisticsModelPointer from "../../../wizard/fields/cfg-statistics-model-pointer";

export default {
  name: "cfg-hier-dictionary",
  components: {
    CfgTemplateModelPointer,
    CfgLogicModelPointer,
    CfgTwinsModelPointer,
    CfgEntityModelPointer,
    CfgEmpty,
    CfgMapWrapper,
    CfgTemplateInstancePointer, CfgStatisticsModelPointer,
    CfgLogicInstancePointer, CfgTwinsInstancePointer, CfgEntityInstancePointer, CfgField,CfgCell
  },
  data(){
    return {
      newValue:''
    }
  },
  computed: {
    lang() {
      return {
        "en-US": {
          id:'id',
          parentId:'parentId',
          name:'name',
          title: 'title',
          model: 'model',
          pointer: 'pointer',
          values: 'value',
          newValue:'new value',
          condition: 'condition',
        },
        "zh-CN": {
          id:'唯一标识',
          parentId:'上一级标识',
          name:'名称',
          title: '显示名称',
          model: '模型',
          pointer: '指针',
          values: '附加值',
          newValue:'新增字段',
          condition: '条件',

        },
      }[this.G_Locale];
    },
    modelList(){
      return this.$modelObject.getModelList(this.G_Locale)
    }
  },
  props:{
    data:{
      default:()=>{
        return {
          // value: {}
        }
      }
    }
  },
  methods:{
    addValue(item){
      if(!!item){
        this.$set(this.data.values,item,'');
        this.newValue='';
      }
    },
    removeValue(item){
      this.$delete(this.data.values,item)
    }
  }
}
</script>

<style scoped>

</style>
